<?php
	session_start( );
	require_once('connections/mysqlDB.php');
	$dbConn = new mysqli(HOST,USER,PWD,DB);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--DVID=00001DE9-->
<HTML>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<LINK href="frmm.css" rel="stylesheet" type="text/css">
<title>慕主先鋒教會</title>
</head>
<?php
$regid=  $_SESSION['regid'];
$email =  $_SESSION['email'];
$fullname= $_SESSION['fullname']; 
?>
<body link=#3060c0 vlink=#3060c0>

<div id="container"> 
  <h1><img src="frmmtitlePic.jpg" width="785" height="75"></h1>


  <div id="thin-col">
登入名(Login as)<br><li><a href="con_registrant.php"><?php echo $_SESSION['fullname']; ?></a>
<p>

<a href=logout.php>登出(Logout)</a>
<hr color=#c0c0c0 size = 1>

特會報名<br>(Registration for)</b><li><?php echo $_SESSION['conferenceID']; ?>
<p>

    <!-- * Be sure to validate your HTML and CSS before including these buttons 
    		 * HTML Validator: http://webdesign.about.com/od/validators/l/bl_validation.htm#htmlvalidator
         * CSS Validator: http://webdesign.about.com/od/validators/l/bl_validation.htm#cssvalidator
    -->

<a href="con_newreg.php"><font size=-1>替別人報名<br>(New Registration)</font></a><br><br>
<a href="con_shareroom.php"><font size=-1>我可以分享床位 Share My Room<br></font></a><br>
<a href="con_findroom.php"><font size=-1>床位 Find A Room<br></font></a><br>
<a href="con_sharecar.php"><font size=-1>我可以分享車位 Car Share<br></font></a><br>
<p>

</div>

<div id="thick-col">

<?php
	$result = mysqli_query($dbConn, "select gender from registrant where email = '$email'");
	$row = mysqli_fetch_array($result);
	$regIdGender = $row['gender'];
	$result = mysqli_query($dbConn, "select ID, NUMBER, (select NAME from HOTEL where ID=HOTEL) AS HOTEL, CHECKIN_DATE, CHECKOUT_DATE 
		from SHARE_ROOM where AVAILABILITY > 0 AND OWNER in (select regid from registrant where gender='$regIdGender')");
	$hasData = FALSE;
	if ($result) {
		while ($row = mysqli_fetch_array($result)) {
			if (!$hasData) {
				echo "Available room(s):<br><br>";
				echo "<table border=\"1\">";
				echo "<tr><td>Hotel Name</td><td>Room #</td><td>Checkin Date</td><td>Checkout Date</td><td>Roommates</td><td>Select</td></tr>";
				$hasData = TRUE;			
			}
			echo "<tr>";
			echo "<td>".$row['HOTEL']."</td>";
			echo "<td>".$row['NUMBER']."</td>";
			echo "<td>".$row['CHECKIN_DATE']."</td>";
			echo "<td>".$row['CHECKOUT_DATE']."</td>";
			
			echo "<td>";
			$roomId = $row['ID'];
			$result2 = mysqli_query($dbConn, "select a.first_name as FIRST_NAME, a.last_name as LAST_NAME, a.email as EMAIL,
				a.mobile_phone as MOBILE_PHONE, b.ISOWNER as ISOWNER from registrant a, ROOMMATE b 
				where a.regid = b.regid and b.ROOMID = '$roomId'");
			echo "<table border=\"1\">";
			echo "<tr><td><font size=-2>First Name</font></td><td><font size=-2>Last Name</font></td><td><font size=-2>Email</font></td>" .
					"<td><font size=-2>Mobile</font></td></tr>";
			while ($row2 = mysqli_fetch_array($result2)) {
				echo "<tr>";
				if ($row2['ISOWNER'] == 1) {
					echo "<td><font size=-2><b>".$row2['FIRST_NAME']."</b></font></td>";
					echo "<td><font size=-2><b>".$row2['LAST_NAME']."</b></font></td>";
					echo "<td><font size=-2><b>".$row2['EMAIL']."</b></font></td>";
					echo "<td><font size=-2><b>".$row2['MOBILE_PHONE']."</b></font></td>";
				} else {
					echo "<td><font size=-2>".$row2['FIRST_NAME']."</font></td>";
					echo "<td><font size=-2>".$row2['LAST_NAME']."</font></td>";
					echo "<td><font size=-2>".$row2['EMAIL']."</font></td>";
					echo "<td><font size=-2>".$row2['MOBILE_PHONE']."</font></td>";
				}
				echo "</tr>";
			}
			echo "</table>";
			echo "</td>";
			
			echo "<td><INPUT TYPE=\"radio\" NAME=\"find_room\" VALUE=\"".$roomId."\"></td>";
			echo "</tr>";
		}
		if ($hasData) {
			echo "</table><br><br>";
		}
	}
?>

<form name="find_room_form" method="post" action="con_findroom_proc.php">

	<p align="center">
		<input type="submit" name="Want This Room" value="Want This Room">
	</p>

</form>

</div> <!-- end of green box ->

</div> <!-- end of container ->

</body>
</html>
